package com.example.filter;

import javax.servlet.*;
import javax.servlet.annotation.WebFilter;
import java.io.IOException;
@WebFilter(urlPatterns={"/*"})
//https://www.jianshu.com/p/aa3e71fdbe4d
//@WebFilter(urlPatterns = {"/**/*.jsp"})
//字符编码过滤器
public class MyFilter implements Filter {
    @Override
    public void init(FilterConfig filterConfig) throws ServletException {
        //System.out.println("过滤器执行了");
    }

    @Override
    public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException {
        request.setCharacterEncoding("gbk");
        response.setCharacterEncoding("gbk");
        response.setContentType("text/html;charset=gbk");
        chain.doFilter(request,response);
    }

    @Override
    public void destroy() {


    }
}
